{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.1. Learning the basics of the Unix shell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "~/git/cookbook-2nd/chapter02_best_practices\n"
     ]
    }
   ],
   "source": [
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "00_intro.md  03_git.md           07_high_quality.md\n",
      "01_shell.md  04_git_advanced.md  08_test.md\n",
      "02_py3       05_workflows.md     09_debugging.md\n",
      "02_py3.md    06_tips.md          images\n"
     ]
    }
   ],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 100\n",
      "-rw-rw-r-- 1 owner   769 Dec 12 10:23 00_intro.md\n",
      "-rw-rw-r-- 1 owner  2473 Dec 12 14:21 01_shell.md\n",
      "...\n",
      "-rw-rw-r-- 1 owner  9390 Dec 12 11:46 08_test.md\n",
      "-rw-rw-r-- 1 owner  5032 Dec 12 10:23 09_debugging.md\n",
      "drwxrwxr-x 2 owner  4096 Aug  1 16:49 images\n"
     ]
    }
   ],
   "source": [
    "ls -l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "cd images"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "~/git/cookbook-2nd/chapter02_best_practices/images"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "folder.png  github_new.png\n"
     ]
    }
   ],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "cd .."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "~/git/cookbook-2nd/chapter02_best_practices"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 20\n",
      "drwxr-xr-x  5 cyrille 4096 Nov 14 16:16 .\n",
      "drwxr-xr-x 93 cyrille 4096 Dec 12 10:50 ..\n",
      "drwxr-xr-x  2 cyrille 4096 Nov 14 16:16 extensions\n",
      "drwxr-xr-x  2 cyrille 4096 Nov 14 16:16 nbextensions\n",
      "drwxr-xr-x  7 cyrille 4096 Dec 12 14:18 profile_default\n"
     ]
    }
   ],
   "source": [
    "ls -la ~/.ipython"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "00_intro.md         05_workflows.md\n",
      "01_shell.md         06_tips.md\n",
      "02_py3.md           07_high_quality.md\n",
      "03_git.md           08_test.md\n",
      "04_git_advanced.md  09_debugging.md\n"
     ]
    }
   ],
   "source": [
    "# We create an empty directory:\n",
    "mkdir md_files\n",
    "# We copy all Markdown files into the new directory:\n",
    "cp *.md md_files\n",
    "# We rename the directory:\n",
    "mv md_files markdown_files\n",
    "ls markdown_files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "rmdir: failed to remove 'markdown_files':\n",
      "    Directory not empty\n"
     ]
    }
   ],
   "source": [
    "rmdir markdown_files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "rm markdown_files/*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "rmdir markdown_files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Learning the basics of the Unix shell\n",
      "\n",
      "Learning how to interact with the operating system (...)\n"
     ]
    }
   ],
   "source": [
    "# Show the first three lines of a text file:\n",
    "head -n 3 01_shell.md"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "We will also cover more general topics (...)\n"
     ]
    }
   ],
   "source": [
    "# Show the last line of a text file:\n",
    "tail -n 1 00_intro.md"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello world!\n"
     ]
    }
   ],
   "source": [
    "# We display some text:\n",
    "echo \"Hello world!\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# We redirect the output of a command to\n",
    "# a text file with `>`:\n",
    "echo \"Hello world!\" > myfile.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello world!\n"
     ]
    }
   ],
   "source": [
    "# We display the entire contents of the file:\n",
    "cat myfile.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Unix shell\n",
      "Unix shell\n",
      "Unix subsystem\n",
      "Unix shell\n",
      "(...)\n",
      "Unix shell\n",
      "Unix shell\n"
     ]
    }
   ],
   "source": [
    "grep -Eo \"Unix \\w+\" 01_shell.md"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Unix shell\n"
     ]
    }
   ],
   "source": [
    "echo \"This is a Unix shell\" | grep -Eo \"Unix \\w+\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
